//fetchBaiduResponse.js
// 异步函数，用于获取百度ERNIE模型的接口回复
async function fetchBaiduResponse(message) {
    const access_token = '24.c82edc279d57da552446e7541d65b109.2592000.1737685279.282335-116650161';
    const url = `https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/text2image/sd_xl?access_token=${access_token}`;
    let body;
    body = JSON.stringify({
        "prompt":message,
        "size":"768x768"
    });
    console.log(body);
    const headers = {
        'Content-Type': 'application/json'
    };
    try {
        const response = await fetch(url, {
            method: 'POST',
            headers: headers,
            body: body
        });
        if (!response.ok) {
            throw new Error(`HTTP error! status: ${response.status}`);
        }
        return response.json();
    } catch (error) {
        console.error('Error fetching Baidu response:', error);
        throw error;
    }
}

async function fetchBaiduResponse_prompt(message) {
    const access_token = '24.c82edc279d57da552446e7541d65b109.2592000.1737685279.282335-116650161';
    const url = `https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/yi_34b_chat?access_token=${access_token}`;
    body = JSON.stringify({
        "messages": [
            {
                "role": "user",
                "content": message
            },
        ]
    });
    const headers = {
        'Content-Type': 'application/json'
    };
    try {
        const response = await fetch(url, {
            method: 'POST',
            headers: headers,
            body: body
        });
        if (!response.ok) {
            throw new Error(`HTTP error! status: ${response.status}`);
        }
        return response.json();
    } catch (error) {
        console.error('Error fetching Baidu response:', error);
        throw error;
    }
}